#!/usr/bin/env python3
# -*- encoding: utf-8 -*-
'''
@File    :   main.py
@Time    :   2023/04/07 22:59:59
@Author  :   youle
@Email   :   a_fly0505@163.com
@Copyright : 侵权必究
'''

import server.route as route
import logging
import sys
import core.utils as utils
from service import Service


def RunApp():
    utils.LogConfig()
    route.Init()
    route.Run()


class TaskService(Service):
    def __init__(self, *args, **kwargs):
        super(TaskService, self).__init__(*args, **kwargs)

    def run(self):
        RunApp()


def RunDaemon(argvs):
    if len(argvs) != 2:
        sys.exit('Syntax: %s COMMAND' % argvs[0])

    cmd = sys.argv[1].lower()
    service = TaskService('my_service', pid_dir='/tmp')

    if cmd == 'start':
        service.start()
    elif cmd == 'stop':
        service.stop()
    elif cmd == 'kill':
        service.kill()
    elif cmd == 'pid':
        print(service.get_pid())
    elif cmd == 'status':
        if service.is_running():
            print("Service is running.")
        else:
            print("Service is not running.")
    else:
        sys.exit('Unknown command "%s".' % cmd)


if __name__ == '__main__':
    # RunDaemon(sys.argv)
    RunApp()
